package com.zzyl.task;


import com.zzyl.service.impl.CustomerReservationServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class reservationTask {
    @Autowired
    private CustomerReservationServiceImpl customerReservationServiceImpl;
    //每小时执行一次
    @Scheduled(cron = "0 0,30  * * * *")
    public void reservationExpiredTask() {
        //1.获取到所有预约的ids
        //TODO 可以改进只判断该时间点一小时以前的所有预约信息
        List<Long> ids = customerReservationServiceImpl.getAll();
        //2.遍历这些ids 判断是否是需要更新状态为过期
        ids.forEach(id ->{
            customerReservationServiceImpl.updateStatusToExpired(id);
        });
    }
}
